<html>
<head><meta charset="utf-8"><title>reorder opts for fun and profit · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html">reorder opts for fun and profit</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211759046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211759046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211759046">(Sep 30 2020 at 13:30)</a>:</h4>
<p>hi <span class="user-mention" data-user-id="262681">@Emanuel Lima</span> </p>
<p>in <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/optimizing.20matches">https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/optimizing.20matches</a> I realized that we have a suboptimal ordering of some optimizations, and if you want, you can use this as a starter issue.</p>



<a name="211759532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211759532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211759532">(Sep 30 2020 at 13:34)</a>:</h4>
<p>hmm... that's weird... SimplifyComparisonIntegral is already after MatchBranchSimplification, but they don't seem to be working hand in hand</p>



<a name="211759784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211759784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emanuel Lima <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211759784">(Sep 30 2020 at 13:36)</a>:</h4>
<p>Nice, I will take a look into it.</p>



<a name="211759987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211759987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211759987">(Sep 30 2020 at 13:37)</a>:</h4>
<p>sec, I have a repro somewhere</p>



<a name="211760097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760097">(Sep 30 2020 at 13:38)</a>:</h4>
<p>some basic initial instructions: add a new example in <code>src/test/mir-opt</code> and read the <code>README.md</code> in the same folder to see how to dump MIR for a specific function</p>



<a name="211760182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760182">(Sep 30 2020 at 13:39)</a>:</h4>
<p>then, you can run all that with <code>./x.py test --bless src/test/mir-opt</code> which will automatically generate said mir dumps</p>



<a name="211760263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760263">(Sep 30 2020 at 13:39)</a>:</h4>
<p>So, here's the repro I was thinking about: <a href="https://godbolt.org/z/Pcjsfc">https://godbolt.org/z/Pcjsfc</a></p>



<a name="211760426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760426">(Sep 30 2020 at 13:40)</a>:</h4>
<p>basically we want that <code>Eq</code> before the <code>switchInt</code> to be gone, and the <code>switchInt</code> to be <code>switchInt(_3, [1: bb2, otherwise: bb1])</code></p>



<a name="211760472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760472">(Sep 30 2020 at 13:41)</a>:</h4>
<p>this is theoretically what the <code>SimplifyComparisonIntegral</code> optimization does</p>



<a name="211760488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760488">(Sep 30 2020 at 13:41)</a>:</h4>
<p>not sure why not in this case</p>



<a name="211760524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760524">(Sep 30 2020 at 13:41)</a>:</h4>
<p>for debugging you can throw a bunch of <code>trace!</code> invocations into the optimization to get to know it better</p>



<a name="211760572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211760572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211760572">(Sep 30 2020 at 13:41)</a>:</h4>
<p>(also make sure to dump the MIR before and after that optimization, so you are always on top of what MIR you're working on)</p>



<a name="211761387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211761387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211761387">(Sep 30 2020 at 13:47)</a>:</h4>
<p>edit: wrong guess, we don't actually exit because of my guess</p>



<a name="211762356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211762356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211762356">(Sep 30 2020 at 13:54)</a>:</h4>
<p>shouldn't <code>SimplifyComparisionIntegral</code> also optimize <a href="https://godbolt.org/z/dhjqdK">https://godbolt.org/z/dhjqdK</a>?</p>



<a name="211768575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/reorder%20opts%20for%20fun%20and%20profit/near/211768575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/reorder.20opts.20for.20fun.20and.20profit.html#211768575">(Sep 30 2020 at 14:32)</a>:</h4>
<p>yes... it should</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>